﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using MySilverlightAlbum.Data;
using System.ComponentModel;

namespace MySilverlightAlbum
{
    public partial class MainMenu : UserControl, INotifyPropertyChanged 
    {
        public event PropertyChangedEventHandler      PropertyChanged;
        public event RoutedEventHandler               Action;

        private ObservableCollection<ImageFolder>     m_menuItems;
        private ImageFolder                           m_doc;

        public MainMenu(
        )
        {
            InitializeComponent();
            m_menuItems = new ObservableCollection<ImageFolder>();

            this.DataContext = this;
        }

        public ImageFolder Document
        {
            get
            {
                return m_doc;
            }
            set
            {
                m_doc = value;
                m_menuItems.Clear();

                if (m_doc != null)
                {
                    foreach (ImageFolder f in m_doc.Children)
                    {
                        m_menuItems.Add(f);
                    }
                }

                menuItems.ItemsSource = m_menuItems;
                Title = m_doc.Title;

                SetChanged("Title");
            }
        }

        public string Title
        {
            get;
            set;
        }

        private void OnMenuClick(
            object                                      sender, 
            RoutedEventArgs                             e
        )
        {
            if (Action != null)
            {
                Action(sender, e);
            }
        }

        private void SetChanged(
            string                                      prop
        )
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(prop));
            }
        }
    }
}
